package com.example.q_kang.hhh.home;

import android.content.res.XmlResourceParser;

import com.example.q_kang.hhh.api.JsonCallBack;
import com.hjq.toast.ToastUtils;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.sskj.base.BasePresenter;
import com.example.q_kang.hhh.home.TeamJiHuoActivity;
import com.sskj.base.api.Constant;
import com.sskj.base.base.HttpData;
import com.sskj.base.bean.JiHuoCommmonBean;


/**
 * @author Hey
 * Create at  2019/04/10
 */
class TeamJiHuoPresenter extends BasePresenter<TeamJiHuoActivity> {

    public void getMyJiHuo() {
        httpService.getMyJiHuo()
                .tag(this)
                .execute(new JsonCallBack<HttpData<JiHuoCommmonBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<JiHuoCommmonBean>> response) {
                        HttpData body = response.body();
                        if (body.getStatus() == Constant.OK) {
                            mView.getJiHuoSuccess((JiHuoCommmonBean) body.getData());
                        }

                    }

                    @Override
                    public void onStart(Request<HttpData<JiHuoCommmonBean>, ? extends Request> request) {
                        super.onStart(request);
                        mView.showLoading();
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }


    public void sendCode(String mobile) {
        httpService.getCode(mobile)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtils.show(httpData.getMsg());
                        if (httpData.getStatus() == Constant.OK) {
                            mView.sendCodeSuccess();
                        }

                    }
                });
    }

    public void jiHuo(String mobile, String code, String pwd) {
        httpService.jiHuo(mobile, code, pwd)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtils.show(body.getMsg());

                    }

                    @Override
                    public void onStart(Request<HttpData, ? extends Request> request) {
                        super.onStart(request);
                        mView.showLoading();
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }

}
